<template>
  <avue-crud :data="data"
             v-model="obj"
             :option="option"
             @error="error"></avue-crud>
</template>
<script>
export default {
  data () {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.obj.password) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    return {
      obj: {},
      data: [],
      option: {
        column: [{
          label: '密码',
          prop: 'password',
          rules: [{ required: true, validator: validatePass, trigger: 'blur' }]
        }, {
          label: '确认密码',
          prop: 'oldpassword',
          rules: [{ required: true, validator: validatePass2, trigger: 'blur' }]
        }]
      }
    };
  },
  methods: {
    error (err) {
      this.$message.success('请查看控制台');
      console.log(err)
    }
  }
}
</script>